<template>
<div style="height:660px;box-sizing:border-box;padding:0 20px;overflow-y: auto; ">
   <el-button class="filter-item" size="mini" type="success" icon="el-icon-back"  @click="backToAdd">返回</el-button>	
  <!-- <div class="head_title">合同信息</div> -->
  <el-form ref="form" :model="form"  style="margin-top: 16px;" size="small" label-width="180px">
	<el-form-item label="申报行"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.declareBank"  :disabled="true" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="申报日期" style="display:inline-block;width:48%;margin-bottom:-2px">
			<el-form-item prop="date1">
					<el-date-picker  type="date"  v-model="form.declareDate"  value-format="yyyy-MM-dd" :disabled="true" style="width: 370px;" ></el-date-picker>
			</el-form-item>			
	</el-form-item>
    <el-form-item label="借款单位(人)名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.custName" :disabled="true" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="借据流水号"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.debitNo"  :disabled="true" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="借款合同号"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.contractNo" :disabled="true" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="借款种类"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.loanType"  :disabled="true" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="担保方式"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.guaranteeMethod" :disabled="true" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="原贷金额"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.contractAmount"  :disabled="true" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="贷款余额"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.balance" :disabled="true" style="width: 370px;"/>
    </el-form-item>
    <!-- <el-form-item label="原借款期限" style="display:inline-block;width:48%;margin-bottom:-2px">
			<el-form-item prop="date1">
					<el-date-picker  type="date"  v-model="form.term" :disabled="true" style="width: 370px;" ></el-date-picker>
			</el-form-item>			
	</el-form-item> -->
    
	<el-form-item label="原借款期限" style="display:inline-block;width:48%;margin-bottom:-2px">
				<el-input v-model="form.term"  :disabled="true" style="width: 370px;"/>	
	</el-form-item>


     <el-form-item label="展期(或重组)情况"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.rolloverReorganize"  :disabled="true" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="本息逾期天数"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.expectedDates" :disabled="true" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="应收未收利息金额"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.shouldNotAmount" :disabled="true" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="已核销额度或已提呆账准备"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.writeOffAmount" :disabled="true"  style="width: 370px;"/>
    </el-form-item>
	<!-- <el-form-item label="原贷款形态"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.oldSortResult" :disabled="true" style="width: 370px;"/>
    </el-form-item> -->

    <el-form-item label="原贷款形态"  prop="deptNum" style="display:inline-block;width:48%;">
            <el-select v-model="form.oldSortResult"  :disabled="true"  placeholder="请先选择业务品种" style="width: 370px;">
				<el-option
					v-for="item in dictMap.level_assetsort"
					:key="item.id"
					:label="item.label"
					:value="item.value"/>
          </el-select>
    </el-form-item>



	<!-- <el-form-item label="调整状态"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.sortResult" :disabled="true" style="width: 370px;"/>
    </el-form-item> -->

	<el-form-item label="调整状态"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-select v-model="form.sortResult"  placeholder="请先选择业务品种" style="width: 370px;">
				<el-option
					v-for="item in dictMap.level_assetsort"
					:key="item.id"
					:label="item.label"
					:value="item.value"/>
          </el-select>
    </el-form-item>



    <el-form-item  label="内部形态调整理由"  style="display:inline-block;width:83.1%;">
            <el-input  type="textarea"  v-model="form.inAdjustReason"  style="width:1170px"></el-input>
    </el-form-item>
    <el-form-item label="支行客户经理"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.branchCustManager" :disabled="true" style="width: 370px;"/>
    </el-form-item>


	 <el-form-item label="上传附件" style="display:inline-block;width:93.1%;">
					  <el-input v-model="uploadForm.excelData" style="width: 370px;"/>
                      <input type="file" @change="ImpData(this)" accept=".jpg,.png"/>
	 </el-form-item>

	 <el-form-item label="">
       <el-button :loading="loading" size="medium" type="primary" @click="makeSure">保存</el-button>
	   <el-button  size="medium" type="" @click="back">取消</el-button>
    </el-form-item>
    



	<!-- <el-form-item label="客户名称"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.custName" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="业务品种"  style="display:inline-block;width:48%;">
           <el-select v-model="form.busiType"  placeholder="请先选择业务品种" style="width: 370px;">
				<el-option
					v-for="item in dictMap.busi_type"
					:key="item.id"
					:label="item.label"
					:value="item.value"/>
          </el-select>
      </el-form-item>
	<el-form-item label="文本合同号"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.paperContractNo" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="合同金额"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.contractAmount" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="币种"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.currency" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="行业投向"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.industryInvest" style="width: 370px;"/>
    </el-form-item>
	<el-form-item  label="用途说明"  style="display:inline-block;width:93.1%;">
            <el-input  type="textarea"  v-model="form.use"  style="width:1170px"></el-input>
    </el-form-item>
	<el-form-item label="基准年利率"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.yearRate" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="利率浮动方式"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.rateFloatMode" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="利率浮动值"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.rateFloatVal" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="执行月利率"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.monthRate" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="利率调整方式"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.rateAdjustMode" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="还款方式"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.repayMode" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="主要担保方式"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.guaranteeMode" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="其他担保方式"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.otherGuaranteeMode" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="合同起始日" style="display:inline-block;width:48%;margin-bottom:-2px">
			<el-form-item prop="date1">
					<el-date-picker  type="date"  v-model="form.contractStart" style="width: 370px;" ></el-date-picker>
			</el-form-item>			
	</el-form-item>
	 <el-form-item label="合同到期日" style="display:inline-block;width:48%;margin-bottom:-2px">
			<el-form-item prop="date1">
					<el-date-picker  type="date"  v-model="form.contractEnd" style="width: 370px;" ></el-date-picker>
			</el-form-item>			
	</el-form-item>
	<el-form-item label="总余额"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.balance" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="逾期天数"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.overdueDays" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="五级分类"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.fiveKind" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="终结日期" style="display:inline-block;width:48%;margin-bottom:-4px">
			<el-form-item prop="date1">
					<el-date-picker  type="date"  v-model="form.endDate" style="width: 370px;" ></el-date-picker>
			</el-form-item>			
	</el-form-item>
    <el-form-item  label="备注"  style="display:inline-block;width:93.1%;">
            <el-input  type="textarea"  v-model="form.remark"  style="width:1170px"></el-input>
    </el-form-item>
    <el-form-item label="录入人"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.createUser" style="width: 370px;"/>
    </el-form-item>
     <el-form-item label="录入机构"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.dept" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="录入日期" style="display:inline-block;width:48%;margin-bottom:-4px">
			<el-form-item prop="date1">
					<el-date-picker  type="date"  v-model="form.createTime" style="width: 370px;" ></el-date-picker>
			</el-form-item>			
	</el-form-item>
    <el-form-item label="更新人"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.updateUser" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="更新机构"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.updateDept" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="更新日期" style="display:inline-block;width:48%;">
			<el-form-item prop="date1">
					<el-date-picker  type="date"  v-model="form.updateTime" style="width: 370px;" ></el-date-picker>
			</el-form-item>			
	</el-form-item> -->
  </el-form>
  </div>
</template>

<script>
import { get, update } from '@/api/alipay'
import { general,list,credentials,addCredentials,effective} from '@/api/custComBaseinfo'
import { contractDetails } from '@/api/loanManageInfo'

import { adjustDetails } from '@/api/assetClassificationInfo'

import initData from '@/mixins/initData'
import initDict from '@/mixins/initDict'
import { parseTime } from '@/utils/index'
import checkPermission from '@/utils/permission'
export default {
  name: 'Config',
  mixins: [initData,initDict],
  data() {
    return {
	  dialog:false,
	  loading: false,
	  addLoading:false,
	  id:'',
	  uploadData:{

	  },
      form: { 
		   custNum:'',
		   custName:'',
		   busiType:'',
		   paperContractNo:'',
		   contractNo:'',
		   contractAmount:'',
		   currency:'',
		   industryInvest:'',
		   use:'',
		   yearRate:'',
		   rateFloatMode:'',
		   rateFloatVal:'',
		   monthRate:'',
		   rateAdjustMode:'',
		   repayMode:'',
		   guaranteeMode:'',
		   otherGuaranteeMode:'',
		   contractStart:'',
		   contractEnd:'',
		   balance:'',
		   overdueDays:'',
		   fiveKind:'',
		   endDate:'',
		   remark:'',
		   createUser:'',
		   dept:'',
		   createTime:'',
		   updateUser:'',
		   updateDept:'',
		   updateTime:'',


  



		   declareBank:'',
		   declareDate:'',
		   custName:'',
		   debitNo:'',
		   contractNo:'',
		   loanType:'',
		   guaranteeMethod:'',
		   contractAmount:'',
		   balance:'',
		   term:'',
		   rolloverReorganize:'',
		   expectedDates:'',
		   shouldNotAmount:'',
		   writeOffAmount:'',
		   oldSortResult:'',
		   sortResult:'',
		   inAdjustReason:'',
		   branchCustManager:'',
          

           excelData:''



		  

 
		 },
		  uploadForm:{
		    excelData:'',
		  
	      },
		  reqForm:{
			page: 0, 
			size: 10,
			sort:'orderNum,asc',
			custId:''
		},
		reqLoading:true,
		reqId:'',
		reqIds:[],
	    addForm:{
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
		},
		addRules: {
				cardCountry: [
				  { required: true, message: '请输入证件国别', trigger: 'blur' }
				],
				cardType: [
				  { required: true, message: '请输入证件类型', trigger: 'blur' }
				],
				cardNum: [
				  { required: true, message: '请输入证件编号', trigger: 'blur' }
				],
				cardEndDate: [
				  { required: true, message: '请输入证件到期日期', trigger: 'blur' }
				],
				cardStatus: [
				  { required: true, message: '请输入证件状态', trigger: 'blur' }
				],
				cardPublishCity: [
				  { required: true, message: '请输入证件发布城市', trigger: 'blur' }
				],
		        isMainCard: [
				  { required: true, message: '请输入是否主证件', trigger: 'blur' }
				]

		},

		effectiveParams:{
		   id:'',
		   cardStatus:''
		},
      rules: {
        appID: [
          { required: true, message: '请输入appID', trigger: 'blur' }
        ],
        sysServiceProviderId: [
          { required: true, message: '请输入商家账号', trigger: 'blur' }
        ],
        privateKey: [
          { required: true, message: '商户私钥不能为空', trigger: 'blur' }
        ],
        publicKey: [
          { required: true, message: '支付宝公钥不能为空', trigger: 'blur' }
        ],
        returnUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ],
        notifyUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
	  console.log('id----',this.$route.params.id)
	  //this.id = this.$route.params.id

     this.$nextTick(() => {
          this.getDictMap('busi_type,level_assetsort')
		  console.log('dictMap-------------',this.dictMap)
	 })
   
      

	  
	//   console.log('id--------------',this.id)
	  	setTimeout(() => {
				 this.id = sessionStorage.getItem('adjustId')
				 //this.reqForm.custId = sessionStorage.getItem('contractNo')
				 console.log('this.id',this.id)
				 this.loading = true
				 let that = this
                 adjustDetails(this.id).then(res => {
					   this.loading = false
					    this.form = {
							declareBank:res.declareBank,
							declareDate:res.declareDate,
							custName:res.custName,
							debitNo:res.debitNo,
							contractNo:res.contractNo,
							loanType:res.loanType,
							guaranteeMethod:res.guaranteeMethod,
							contractAmount:res.contractAmount,
							balance:res.balance,
							term:res.term,
							rolloverReorganize:res.rolloverReorganize,
							expectedDates:res.expectedDates,
							shouldNotAmount:res.shouldNotAmount,
							writeOffAmount:res.writeOffAmount,
							oldSortResult:res.oldSortResult,
							sortResult:res.sortResult,
							inAdjustReason:res.inAdjustReason,
							branchCustManager:res.branchCustManager,
							applyNo:res.applyNo
							

						}
						
						//this.uploadForm.excelData = res.file.fileName
						this.uploadForm.excelData = res.file ==null?null:res.file.fileName
						
					  // that.form = res
                    //   this.form = {
					// 	    custNum:res.custNum,
					// 		custName:res.custName,
					// 		busiType:res.busiType,
					// 		paperContractNo:res.paperContractNo,
					// 		contractNo:res.contractNo,
					// 		contractAmount:res.contractAmount,
					// 		currency:res.currency,
					// 		industryInvest:res.industryInvest,
					// 		use:res.use,
					// 		yearRate:res.yearRate,
					// 		rateFloatMode:res.rateFloatMode,
					// 		rateFloatVal:res.rateFloatVal,
					// 		monthRate:res.monthRate,
					// 		rateAdjustMode:res.rateAdjustMode,
					// 		repayMode:res.repayMode,
					// 		guaranteeMode:res.guaranteeMode,
					// 		otherGuaranteeMode:res.otherGuaranteeMode,
					// 		contractStart:res.contractStart,
					// 		contractEnd:res.contractEnd,
					// 		balance:res.balance,
					// 		overdueDays:res.overdueDays,
					// 		fiveKind:res.fiveKind,
					// 		endDate:res.endDate,
					// 		remark:res.remark,
					// 		createUser:res.createUser,
					// 		dept:res.dept,
					// 		createTime:res.createTime,
					// 		updateUser:res.updateUser,
					// 		updateDept:res.updateDept,
					// 		updateTime:res.updateTime,
					//   }
					  console.log('this.form',this.form)

				
					   console.log('res',res)
                 }).catch(err => {
                       this.loading = false
                       console.log(err.response.data.message)
				}) 
				


                
			   






         }, 500)
	  
  },
  methods: {
	   parseTime,
	   checkPermission,
	back(){
		 this.$router.go(-1)
	},
	handleSelectionChange(val) {
		  console.log('val',val)
		   val.forEach((v) => {
               this.reqIds.push(v.id)
		   });
		   console.log('ids',this.reqIds)
		   this.reqId = this.reqIds.toString()
		   this.reqIds = []
	},
	add(){
		this.dialog = true;
	},
	cancelAdd(){
		this.resetForm()
	},
	makeSure(){
		console.log(this.uploadData)
		// console.log('this.uploadForm.excelData',this.uploadForm.excelData.split(".")[1])
		// var extension = this.uploadForm.excelData.split(".")[1]
		// if(extension != 'ftl'){
		// 	this.$message.warning('文件类型为ftl')
		// 	return;
		// }
		this.uploadRequest.post("api/assetsort/assetCertificateTemp",this.uploadData).then(res=>{
			  this.$message.success('调整成功！')
			  this.$router.push({ name: "applyAdds" })  
		})
	},
	backToAdd(){
		this.$router.push({ name: "applyAdds" })  
	},
	ImpData(obj){
 
	 var file = event.currentTarget.files[0];
	 console.log('tttttt',file.name)
	 this.form.excelData = file.name
	 this.uploadForm.excelData = file.name

	 console.log('this.form.excelData',this.form.excelData)
	 console.log('this.form.declareBank',this.form.declareBank)
	 console.log('this.form.debitNo',this.form.debitNo)
	 console.log('tttttt====',file)
	 let data = new FormData();
	  data.append("file",file)
	  data.append("declareBank",this.form.declareBank)
	  data.append("declareDate",this.form.declareDate)
	  data.append("debitNo",this.form.debitNo)
	  data.append("oldSortResult",this.form.oldSortResult)
	  data.append("inAdjustReason",this.form.inAdjustReason)
	  data.append("branchCustManager",this.form.branchCustManager)
      data.append("sortResult",this.form.sortResult)  
	  data.append("applyNo",this.form.applyNo)
	 // data.append("custId",sessionStorage.getItem('comCustId'))
	 this.uploadData  = data
			console.log(this.uploadData)
		//	this.form.excelData = file.name
		return
	  this.form.excelData = event.currentTarget.files[0].name
	  console.log('this.file',event.currentTarget.files)
      var rABS = false; //是否将文件读取为二进制字符串
      var f = this.file;
      var reader = new FileReader();
      FileReader.prototype.readAsBinaryString = function(f) {
      var binary = "";
      var wb; //读取完成的数据
      var outdata;
	  var reader = new FileReader();
	 
      reader.onload = (e)=> {
		   console.log('jjj',e.target.result)
		   console.log('pp',typeof e.target.result)
		//    var a = e.target.result;
		//    var b =new Buffer(a.split(',')[1], 'base64');
		//    console.log('b',b)
		
        

		//    this.reqForm.id = sessionStorage.getItem('comCustId')
		   
		//    const custId = sessionStorage.getItem('comCustId')
		  // const file = e.target.result
          

			




          var bytes = new Uint8Array(reader.result);
          var length = bytes.byteLength;
          for(var i = 0; i < length; i++) {
               binary += String.fromCharCode(bytes[i]);
          }
          var XLSX = require('xlsx');
          wb = XLSX.read(binary, {
             type: 'binary'
		  });
		  console.log('wb',wb)
		  outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); 
		  console.log('outdata',outdata)
          outdata.map(v => {
               let obj = {}
               obj.name= v.名称
               obj.unit = v.单位
               obj.use = v.用途
               _this.excelData.push(obj)
          })
          // _this.reload();
           }
           reader.readAsArrayBuffer(f);
          }
           reader.readAsBinaryString(f);
	},
	resetForm() {
      this.dialog = false
	  this.$refs['forms'].resetFields()
	  this.addForm ={
           custId:'',

		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
	  }
	},
	
 

  }
}
</script>

<style scoped> 
  .head_title{
    height:40px;line-height:40px;border-bottom: 2px solid #ce2731;color:#ce2731
  }
  .space{
	  margin-top:30px;
	  margin-bottom:10px
  }
   .one{
	   display:inline-block;
	   width:86.5%;
   }
   .two{
	   display:inline-block;
	   width:50%;
	
   }


</style>
